/*
 * Created by JFormDesigner on Wed Nov 30 11:24:09 EET 2011
 */

package tr.gov.tubitak.bilgem.esya.certviewer;

import javax.swing.border.*;

import tr.gov.tubitak.bilgem.esya.certviewer.viwerasn.ECertViewerCertificate;

import javax.swing.*;
import javax.swing.border.SoftBevelBorder;
import java.awt.*;
import java.security.cert.X509Certificate;
import java.util.ResourceBundle;

/**
 * @author Haydar Karabas
 */
public class ECertGeneralViewPanel extends JPanel {
     byte [] certData;
    public ECertGeneralViewPanel(X509Certificate x509Certificate) throws Exception {
        initComponents();
        this.certData=certData;
        loadCert(x509Certificate);
    }


    static String getTitle()
    {
        return Bundle.getString("ECertGeneralViewPanel.tabName");
    }

    void loadCert(X509Certificate x509Certificate)
    {
            ECertViewerCertificate eCertViewerCertificate = new ECertViewerCertificate(x509Certificate);
            lblSubjectValue.setText(eCertViewerCertificate.getSubject().toTitle());
            lblIssuerValue.setText(eCertViewerCertificate.getIssuer().toTitle());
            lblKeyUsageValue.setText(eCertViewerCertificate.getKeyUsageListTitle());

            lblValidFromValue.setText(eCertViewerCertificate.getValidFromTitle());
            lblValidToValue.setText(eCertViewerCertificate.getValidToTitle());

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        panel5 = new JPanel();
        panelGeneral = new JPanel();
        panel2 = new JPanel();
        panel1 = new JPanel();
        lblCertInfoIcon = new JLabel();
        lblCertInfo = new JLabel();
        separator1 = new JSeparator();
        panel3 = new JPanel();
        lblKeyUsage = new JLabel();
        scrollPane1 = new JScrollPane();
        lblKeyUsageValue = new JLabel();
        separator2 = new JSeparator();
        panel4 = new JPanel();
        lblSubject = new JLabel();
        lblSubjectValue = new JLabel();
        lblIssuer = new JLabel();
        lblIssuerValue = new JLabel();
        lblValidFrom = new JLabel();
        lblValidFromValue = new JLabel();
        lblValidTo = new JLabel();
        lblValidToValue = new JLabel();

        //======== this ========
        setBorder(null);
        setLayout(new BorderLayout());

        //======== panel5 ========
        {
            panel5.setBorder(new EmptyBorder(10, 10, 10, 10));
            panel5.setLayout(new BoxLayout(panel5, BoxLayout.X_AXIS));

            //======== panelGeneral ========
            {
                panelGeneral.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED));
                panelGeneral.setLayout(new BoxLayout(panelGeneral, BoxLayout.Y_AXIS));

                //======== panel2 ========
                {
                    panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));

                    //======== panel1 ========
                    {
                        panel1.setLayout(new FlowLayout(FlowLayout.LEFT));

                        //---- lblCertInfoIcon ----
                        lblCertInfoIcon.setIcon(new ImageIcon(getClass().getResource("/tr/gov/tubitak/bilgem/esya/certviewer/images/certificate_large.png")));
                        panel1.add(lblCertInfoIcon);
                        panel1.add(lblCertInfo);
                    }
                    panel2.add(panel1);

                    //---- separator1 ----
                    separator1.setBorder(null);
                    panel2.add(separator1);
                }
                panelGeneral.add(panel2);

                //======== panel3 ========
                {
                    panel3.setBorder(new EmptyBorder(3, 3, 3, 3));
                    panel3.setLayout(new BorderLayout());

                    //---- lblKeyUsage ----
                    lblKeyUsage.setFont(lblKeyUsage.getFont().deriveFont(lblKeyUsage.getFont().getStyle() | Font.BOLD));
                    panel3.add(lblKeyUsage, BorderLayout.PAGE_START);

                    //======== scrollPane1 ========
                    {
                        scrollPane1.setBorder(null);

                        //---- lblKeyUsageValue ----
                        lblKeyUsageValue.setVerticalAlignment(SwingConstants.TOP);
                        scrollPane1.setViewportView(lblKeyUsageValue);
                    }
                    panel3.add(scrollPane1, BorderLayout.CENTER);
                }
                panelGeneral.add(panel3);
                panelGeneral.add(separator2);

                //======== panel4 ========
                {
                    panel4.setAutoscrolls(true);
                    panel4.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
                    panel4.setBorder(new EmptyBorder(5, 5, 5, 5));
                    panel4.setLayout(new GridBagLayout());
                    ((GridBagLayout)panel4.getLayout()).columnWidths = new int[] {0, 0, 0};
                    ((GridBagLayout)panel4.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0};
                    ((GridBagLayout)panel4.getLayout()).columnWeights = new double[] {0.4, 1.0, 1.0E-4};
                    ((GridBagLayout)panel4.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0, 1.0, 1.0E-4};

                    //---- lblSubject ----
                    lblSubject.setFont(lblSubject.getFont().deriveFont(lblSubject.getFont().getStyle() | Font.BOLD));
                    panel4.add(lblSubject, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));
                    panel4.add(lblSubjectValue, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));

                    //---- lblIssuer ----
                    lblIssuer.setFont(lblIssuer.getFont().deriveFont(lblIssuer.getFont().getStyle() | Font.BOLD));
                    panel4.add(lblIssuer, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));
                    panel4.add(lblIssuerValue, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));

                    //---- lblValidFrom ----
                    lblValidFrom.setFont(lblValidFrom.getFont().deriveFont(lblValidFrom.getFont().getStyle() | Font.BOLD));
                    panel4.add(lblValidFrom, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));
                    panel4.add(lblValidFromValue, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));

                    //---- lblValidTo ----
                    lblValidTo.setFont(lblValidTo.getFont().deriveFont(lblValidTo.getFont().getStyle() | Font.BOLD));
                    panel4.add(lblValidTo, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));
                    panel4.add(lblValidToValue, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));
                }
                panelGeneral.add(panel4);
            }
            panel5.add(panelGeneral);
        }
        add(panel5, BorderLayout.CENTER);

        initComponentsI18n();
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    private void initComponentsI18n() {
        // JFormDesigner - Component i18n initialization - DO NOT MODIFY  //GEN-BEGIN:initI18n
        ResourceBundle bundle = Bundle.getBundle();
        lblCertInfo.setText(bundle.getString("ECertGeneralViewPanel.lblCertInfo.text"));
        lblKeyUsage.setText(bundle.getString("ECertGeneralViewPanel.lblKeyUsage.text"));
        lblKeyUsageValue.setText(bundle.getString("ECertGeneralViewPanel.lblKeyUsageValue.text"));
        lblSubject.setText(bundle.getString("ECertGeneralViewPanel.lblSubject.text"));
        lblIssuer.setText(bundle.getString("ECertGeneralViewPanel.lblIssuer.text"));
        lblValidFrom.setText(bundle.getString("ECertGeneralViewPanel.lblValidFrom.text"));
        lblValidTo.setText(bundle.getString("ECertGeneralViewPanel.lblValidTo.text"));
        // JFormDesigner - End of component i18n initialization  //GEN-END:initI18n
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel5;
    private JPanel panelGeneral;
    private JPanel panel2;
    private JPanel panel1;
    private JLabel lblCertInfoIcon;
    private JLabel lblCertInfo;
    private JSeparator separator1;
    private JPanel panel3;
    private JLabel lblKeyUsage;
    private JScrollPane scrollPane1;
    private JLabel lblKeyUsageValue;
    private JSeparator separator2;
    private JPanel panel4;
    private JLabel lblSubject;
    private JLabel lblSubjectValue;
    private JLabel lblIssuer;
    private JLabel lblIssuerValue;
    private JLabel lblValidFrom;
    private JLabel lblValidFromValue;
    private JLabel lblValidTo;
    private JLabel lblValidToValue;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
